package com.panfeng.xcloud.boss.provider.assets.service.impl;

import com.alibaba.fastjson.JSON;
import com.panfeng.xcloud.boss.provider.assets.dao.mapper.UserWalletInfoMapperExt;
import com.panfeng.xcloud.boss.provider.assets.dao.mapper.WalletAssetsFlowMapperExt;
import com.panfeng.xcloud.boss.provider.assets.dao.mapper.WithdrawLogMapperExt;
import com.panfeng.xcloud.boss.provider.assets.dto.WalletAssetsFlowExtendItemDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.QueryWalletAssetsFlowPageReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.QueryWalletAssetsFlowPageRespDTO;
import com.panfeng.xcloud.boss.provider.assets.service.IWalletAssetsFlowService;
import com.panfeng.xcloud.common.core.page.PageResponse;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.dao.assets.entity.WalletAssetsFlow;
import com.panfeng.xcloud.dao.base.MapperSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class WalletAssetsFlowServiceImpl extends MapperSupport<Integer, WalletAssetsFlow, WalletAssetsFlowMapperExt> implements IWalletAssetsFlowService {

    @Autowired
    private WalletAssetsFlowMapperExt walletAssetsFlowMapperExt;

    @Autowired
    private WithdrawLogMapperExt withdrawLogMapperExt;

    @Autowired
    private UserWalletInfoMapperExt userWalletInfoMapperExt;

    /**
     * 查询相关资产流水
     *
     * @param queryWalletAssetsFlowPageReqDTO
     * @return
     */
    @Override
    public PageResponse<QueryWalletAssetsFlowPageRespDTO> queryWalletAssetsFlow(QueryWalletAssetsFlowPageReqDTO queryWalletAssetsFlowPageReqDTO) {
        PageResponse<WalletAssetsFlowExtendItemDTO> pageResponse = super.selectPage(queryWalletAssetsFlowPageReqDTO, walletAssetsFlowMapperExt::queryWalletAssetsFlowExtPageCount, walletAssetsFlowMapperExt::queryWalletAssetsFlowExtPage);

        List<WalletAssetsFlowExtendItemDTO> items = pageResponse.getItems();
        log.info(">>>> queryWalletAssetsFlow-items.list：{} <<<", (null != items ? JSON.toJSONString(items) : ""));
        List<QueryWalletAssetsFlowPageRespDTO> queryWalletAssetsFlowRespDTOS = ConvertUtils.convert(items, QueryWalletAssetsFlowPageRespDTO.class);

        PageResponse<QueryWalletAssetsFlowPageRespDTO> pageFinalResponse = new PageResponse();
        pageFinalResponse.setTotalCount(pageResponse.getTotalCount());
        pageFinalResponse.measureTotalPage(pageResponse.getTotalCount(), pageResponse.getPageSize());
        pageFinalResponse.setItems(queryWalletAssetsFlowRespDTOS);
        pageFinalResponse.setPageNumber(pageResponse.getPageNumber());
        pageFinalResponse.setPageSize(pageResponse.getPageSize());

        return pageFinalResponse;
    }

}
